//公共方法
export const globalfun = {
	getCode(){
		uni.login({
			provider: 'weixin',
			success: function(loginRes) {
				console.log(loginRes,'------');
				if(loginRes.errMsg=="login:ok"){
					return loginRes.code
				}
			}
		});
	},
	splitNumber: value => {
		const str = String(value).trim();
		const parts = str.split('.');
		return {
			integer: parts[0] || (str.startsWith('.') ? '0' : ''),
			decimal: parts.length > 1 ? parts[1] : null
		};
	},
	previewImage(list,index){
		uni.previewImage({
			current:index,
			urls:list,
			longPressActions: {
				itemList: ['发送给朋友', '保存图片', '收藏'],
				success: function(data) {
					console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
				},
				fail: function(err) {
					console.log(err.errMsg);
				}
			}
		});
	},
	pageGo: url => {
		uni.navigateTo({
			url
		})
	},
	phoneCall: number => {
		uni.makePhoneCall({
			phoneNumber: number, //仅为示例
			success: function() {
				console.log('success');
			},
			fail: (err) => {
				// uni.showToast({
				// 	icon:'none',
				// 	title:'手机号错误'
				// })
			}
		});
	},
	opennavigation: data => {
		uni.openLocation({
			latitude: parseFloat(data.latitude),
			longitude: parseFloat(data.longitude),
			success: function() {
				console.log('success');
			},
			fail: (err) => {
				uni.showToast({
					icon:'none',
					title:'位置信息错误'
				})
			}
		});
	},
	pageLogin: url => {
		if (uni.getStorageSync('userToken')) {
			
		} else {
			uni.navigateTo({
				url: '/pages/login/login'
			})
			return
		}
	},
	copyFun: data =>{
		uni.setClipboardData({
			data,   // 要复制的内容
			success: () => {  // 复制成功回调
			console.log('11');
				uni.showToast({
					title: '已复制',
					icon: 'success'
				})
			}
		});
	},
}